$(function() {
	require(['inputdrop',
   'tree',
   'tab',
   'plot',
   'workorder',
   'event'] ,function (inputdrop ,tree ,tab ,plot ,workorder ,pevent){
   		var paramObj = {};
   		var key;
   		$("#searchIcon").click(function() {
        key = $("#searchKey").val();
        paramObj.keyWords = key;
        selected_asset_list_get({
          paramObj: paramObj,
          isLoad: true,
          maskObj: "body"
        });
      });

   		selected_asset_list_get({
        paramObj: paramObj,
        isLoad: true,
        maskObj: "body"
      });

   		xd_ajax_get({
				url : 'api/app/getAppTypeCountList',
				isLoad : false,
				successCallBack : function (data){
					var treeData = [
						{
							id: '-1',
							label: ''
						}
					];
					var totalAppCount = 0;
					for (var i = 0; i < data.length; i++) {
						totalAppCount += +data[i].appCount;
						treeData.push({
							id: data[i].typeName,
							label: data[i].typeName + '(' + data[i].appCount + ')'
						});
					}

					treeData[0].label = '全部应用' + '(' + totalAppCount + ')';

					tree.simpleTree($("#monitor_tree_1") ,{
						zNodes: treeData,
						zTreeOnClick : function (treeNode){
							paramObj.type = treeNode.id == -1 ? '' : treeNode.id;
							selected_asset_list_get({
								paramObj: paramObj,
				        isLoad: true,
				        maskObj: "body"
							});
						},
						initIdVal : '-1'
					})
				}
			});

   		// 初始化左侧树数据
		 	function tree_get(currentNode) {
		    var self = this;
		    var left_nav_tree_url;
		    paramObj = {};
		    left_nav_tree_url = "api/property/countBySystem";
		    xd_ajax_get({
		      url: left_nav_tree_url,
		      isLoad: true,
		      successCallBack: function(data1) {
		        var data;
		        current_selected_node_id = '-1';
		        if (currentNode) {
		          current_selected_node_id = currentNode;
		        }
		        tree.render($("#accordion"), {
		          label: "label",
		          id: "id",
		          zNodes: data1,
		          expandNode: "-1",
		          selectNode: current_selected_node_id,
		          zTreeOnClick: function(event, treeId, treeNode) {
		            current_selected_node_id = treeNode.id;
		            current_selected_node_name = treeNode.label;
		            if (list_current_data_name == "assetType") {
		              paramObj.typeId = current_selected_node_id;
		            } else {
		              paramObj.systemId = current_selected_node_id;
		            }
		            selected_asset_list_get({
		              paramObj: paramObj,
		              isLoad: true,
		              maskObj: "body"
		            });
		          }
		        });

		        var treeObj = $("#accordion").data("tree").getSelectedNodes()[0];

		        selected_asset_list_get({
		          paramObj: paramObj,
		          isLoad: true,
		          maskObj: "body"
		        });
		      }
		    });
		  }
	    
	    // 初始化表格数据内容
	    function selected_asset_list_get(opt) {
	      var list_url;
	      var header = [
	        { text: "", name: "t", width: 3, hideSearch: "hide" },
	        { text: "应用图标", name: "logo", width: 10, align: "left",render: function (data) {
	        	return '<img src="' + data + '" class="app_logo">'
	        }},
	        { text: "应用名称", name: "name", width: 15, align: "center"},
	        { text: "版本号", name: "version", width: 15, align: "left" },
	        { text: "应用类型", name: "type", width: 15, align: "left" },
	        {
	          text: "发布时间",
	          name: "createTime",
	          width: 15,
	          align: "left",
	          render: function (data) {
	          	return data?new Date(parseInt(data)).Format('yyyy-MM-dd'):"";
	          }
	        },
	        { text: "开发商", name: "developer", width: 15, align: "left" },
	        { text: "管控域名称", name: "systemName", width: 15, align: "left",tip:true},
	        { text: "部署网络", name: "networkName", width: 15, align: "left" ,tip:true},
	        { text: "应用状态", name: "state", width: 15, align: "left" },
	        { text: "下载量", name: "downNum", width: 15, align: "left" }
	      ];

	      list_url = "api/app/list";
				$("input[placeholder]").placeholder();				
	      g_grid.render($("#table_div1"), {
	        header: header,
	        operWidth: "90px",
	        url: list_url,
	        type:'xd',
	        dataKey: 'list',
	        paramObj: opt.paramObj,
	        hasBorder : false,
	        hideSearch: true,
	        maskObj: opt.maskObj,
	        isLoad: opt.isLoad,
	        dbIndex: 1,
	        autoHeight : true,
	        showCount : true,
	        allowCheckBox: false
	      });
	    }

	    // 初始化筛选
	    xd_ajax_get({
				url: "api/dic/getDicList",
				paramObj: { parentCode: "SYS_NETWORK_CODE" },
				isLoad: true,
				successCallBack: function(data) {
					var dataList = [];
					data ? (dataList = []) : (data = []);
					data.forEach(function(item) {
					dataList.push({ value: item.code, text: item.name });
					}, this);

					xd_ajax_get({
						url: "api/dic/getDicList",
						paramObj: { parentCode: "APP_STATUS" },
						isLoad: true,
						successCallBack: function(data1) {
							var dataList1 = [];
							data1 ? (dataList1 = []) : (data1 = []);
							data1.forEach(function(item) {
							dataList1.push({ value: item.code, text: item.name });
							}, this);
							g_formel.list_filter_render($("um-filter") ,{
								condition : [
									{
										text : "应用状态" ,
										name : "state" ,
										data : dataList1
									},
									{
										text : "部署网络" ,
										name : "networkCode" ,
										data : dataList
									}
								],
								click : function (paramObj){
									debugger									
									g_grid.refresh($("#table_div1") ,{
										paramObj : paramObj
									})
								}
							})
						}
					});
				}
			});
	  });
})